<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>标题</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <link rel="stylesheet" href="/lib/jqueryZtree/3.5.12/css/zTreeStyle/zTreeStyle.min.css">
    <script type="text/javascript" src="/lib/jquery/jquery.js" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/jqueryZtree/3.5.12/js/jquery.ztree.all-3.5.js"></script>
    <script type="text/javascript" src="/lib/mxDraw/mxcustom.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<!--
图纸目录树
-->
<div class="layui-row" style="height: 100%">
    <div class="layui-col-xs2" style="height: 100%">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">选择工区：</label>
                <div class="layui-input-inline" style="width: 120px;">
                    <select lay-search  name="workArea" id="workArea" autocomplete="off" class="layui-input" lay-filter="workAreaChange">
                    </select>
                </div>
            </div>
        </div>
        <div id="drawingDirTree" class="ztree"></div>
    </div>
    <div id="content" class="layui-col-xs10">
        <table class="layui-hide" id="dataList" lay-filter="dataList"></table>
    </div>
</div>



<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="analysis">分析</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    layui.use(['jquery', 'configureCom', 'form','configure', 'sessionFun', 'table','ztree','treeSelect','mxDraw','matchType'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var ztree = layui.ztree;
        var treeSelect = layui.treeSelect;
        var form = layui.form;
        var token=localStorage.getToken;
        var matchType = layui.matchType;
        var mxDraw = layui.mxDraw;
        var configureCom = layui.configureCom;

        //var areaId = configureCom.GetQueryString('areaId');

        var prjId = sessionFun.get('prjId');

        //获取一级工区,初始化 工区下拉框
        configureCom.getAjax(configure.PRJ_WORK_AREA_LIST_API,{ prjId:prjId, parentId:'0'}).then(function (res) {
            $.each(res.data, function(idx, obj) {
                $("#workArea").append('<option value="'+obj.areaId+'">'+obj.areaName+'</option>');
            });
            form.render();
            if(res.data && res.data.length >0 ){
                showByAreaId(res.data[0].areaId);
            }
        });

        //先择工区 - 显示图纸目录和图纸列表
        form.on('select(workAreaChange)', function(data){
            showByAreaId(data.value);
        });

        var cols = [[
            {type: 'checkbox'},
            {title: '序号', type: 'numbers'},
            {field: 'name', width:350, title: '图纸名称'},
            {fixed: 'right', title: '操作',width:150, toolbar: '#barDemo', width: 120}
        ]];
        /**
         * 每行操作
         */
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            //sessionFun.set(configure.SESSION_DRAWING_DATA, data);
            // 查看图纸
            if (obj.event === 'analysis') {
                top.layer.open({
                    type: 2,
                    title: '图纸分析',
                    area: configureCom.Psize1,
                    content:  '/pages/drawingAnalysis/drawingAnalysis.html'+'?fileId='+data.id+'&fileType='+matchType.init(data.name),
                    success: function (layero, index) {
                        top.layer.full(index);
                    }
                });
            }
        });


        /**
         * 显示图纸目录结构和图纸列表
         */
        function showByAreaId(workAreaId){
            deptZtreeFun(workAreaId);
            configureCom.tableRenderGet(configure.PRJ_WORK_AREA_DRAWING_GET_API, {areaId: workAreaId}, cols, 'dataList', 10, 'full-100', 'toolbar', false);
        }


        /**
         * 图纸目录树状结构显示
         */
        var selectDirId = null;
        var docId = null
        function deptZtreeFun(workAreaId) {
            //ztree初始化
            configureCom.getAjax(configure.PRJ_WORK_AREA_DRAWING_DIR_TREE_API,{areaId:workAreaId}).then(function (res) {
                var data = res.result;
                if(data!=null && data.length >0 ){
                    docId = data[0].docId;
                }
                ztree.param.multiCheck = false; //是否多选
                ztree.param.idKey = 'id';           //父级id
                ztree.param.pIdKey = 'parentId';    //子级中与父级id关联
                ztree.param.rootPId = null;         //根节点id
                ztree.param.name = 'name';
                ztree.param.onClick = function(event, treeId, treeNode){
                    // if('att'===treeNode.type){
                    //     var attUrl = 'http://localhost:8081/api/sys/doc/att/'+treeNode.id+'?token='+token;
                    //     mxDraw.init('drawingId', attUrl, 'http://www.mxdraw.com/MxDrawX52.CAB#version=8.0.0.1', '#content');
                    // }


                    selectDirId = treeNode.id;
                    configureCom.tableReload(false,{dirId:selectDirId});
                }
                ztree.init('drawingDirTree', '', data);
            });
        };


    });

</script>
</body>
</html>